import router from './router'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { Toast } from 'vant';
import { userSn, getToken, onBackPressed } from './utils/APPempower'

Vue.prototype.$onBackPressed = onBackPressed

NProgress.configure({ showSpinner: false }) // NProgress Configuration

const whiteList = ["/market"] // no redirect whitelist

router.beforeEach(async (to, from, next) => {
  NProgress.start()
  if (whiteList.indexOf(to.path) !== -1) {
    var toast = Toast.loading({
      duration: 0,
      forbidClick: true,
      message: "加载中...",
    });
    next()
  } else {
    if (userSn() && getToken()) {
      var toast = Toast.loading({
        duration: 0,
        forbidClick: true,
        message: "加载中...",
      });
      document.title = to.meta.title
      next()
    }
  }
})


router.afterEach(() => {
  // finish progress bar
  NProgress.done()
  Toast.clear();
})
